package nwpu.lizhiwen.system;

import nwpu.lizhiwen.houserent.domain.House;
import nwpu.lizhiwen.houserent.utils.Utility;

import java.util.Scanner;

public class SystemView {
    private String key  ;
    private boolean judgment = true;
    private ActivitySystem activitySystem = new ActivitySystem(50);
    private UserSystem userSystem = new UserSystem(50);
    Scanner scanner = new Scanner(System.in);
    private static Scanner scanner1 = new Scanner(System.in);


    /**
     * 功能：读取键盘输入的指定长度的字符串或默认值，如果直接回车，返回默认值，否则返回字符串
     * @param limit 限制的长度
     * @param defaultValue 指定的默认值
     * @return 指定长度的字符串
     */
    public static String readString(int limit, String defaultValue) {
        String str = readKeyBoard(limit, true);
        return str.equals("")? defaultValue : str;
    }
    /**
     * 功能： 读取一个字符串
     * @param limit 读取的长度
     * @param blankReturn 如果为true ,表示 可以读空字符串。
     * 					  如果为false表示 不能读空字符串。
     *
     *	如果输入为空，或者输入大于limit的长度，就会提示重新输入。
     * @return
     */
    private static String readKeyBoard(int limit, boolean blankReturn) {

        //定义了字符串
        String line = "";

        //scanner.hasNextLine() 判断有没有下一行
        while (scanner1.hasNextLine()) {
            line = scanner1.nextLine();//读取这一行

            //如果line.length=0, 即用户没有输入任何内容，直接回车
            if (line.length() == 0) {
                if (blankReturn) return line;//如果blankReturn=true,可以返回空串
                else continue; //如果blankReturn=false,不接受空串，必须输入内容
            }

            //如果用户输入的内容大于了 limit，就提示重写输入
            //如果用户如的内容 >0 <= limit ,我就接受
            if (line.length() < 1 || line.length() > limit) {
                System.out.print("输入长度（不能大于" + limit + "）错误，请重新输入：");
                continue;
            }
            break;
        }

        return line;
    }

    //此处add/del方法逻辑相同，故只对addOrganizerToActivity，delOrganizerToActivity做注释
    //此方法实现将主办方添加进活动
    public void addOrganizerToActivity(){
        System.out.println("请输入主办方的id: ");
        String organizerId = scanner.next();
        System.out.println("请输入主办方要加入的活动id: ");
        String activityId = scanner.next();
        //通过activitySystem类中的find方法找到所要使用的activity
        Activity activity = activitySystem.find(activityId);
        //通过userSystem类中的find方法找到所要使用的organizer，不过此时传出的是user类型，故需要将其向下转型为organizer类才能使用其方法
        Organizer organizer = (Organizer) userSystem.find(organizerId);
        //几个if语句分别判断所需要的用户和活动是否存在
        if ((activity != null) && (organizer != null)){
            //通过activity类中的addOrganizer方法将指定的organizer加入到activity中
            activity.addOrganizer(organizer);
        }else {
            if (activity ==null) {
                System.out.println("---------------该活动不存在-----------------");
            }
            if (organizer == null){
                System.out.println("---------------该用户不存在-----------------");
            }
        }
    }
    //此方法实现将活动中的主办方删除
    public void delOrganizerToActivity(){
        System.out.println("请输入要删除主办方的活动id: ");
        String activityId = scanner.next();
        System.out.println("请输入主办方的id: ");
        String organizerId = scanner.next();
        //通过activitySystem类中的find方法找到所要使用的activity
        Activity activity = activitySystem.find(activityId);
        if (activity == null){
            System.out.println("---------------查找活动不存在-----------------");
            return;
        }
        //调用activity类的delOrganizer方法返回一个boolean值，若为true则删除成功，false则失败
        if (activity.delOrganizer(organizerId)) {
            System.out.println("---------------删除成功-----------------");
        } else {
            System.out.println("--------------id不存在，删除失败-------------------");
        }
    }

    public void addTeacherToActivity(){
        System.out.println("请输入老师的id: ");
        String techerId = scanner.next();
        System.out.println("请输入老师要加入的活动id: ");
        String activityId = scanner.next();
        Activity activity = activitySystem.find(activityId);
        Teacher teacher = (Teacher) userSystem.find(techerId);
       if ((activity != null) && (teacher != null)){
            activity.addTeacher(teacher);
        }else {
            if (activity ==null) {
                System.out.println("---------------该活动不存在-----------------");
            }
            if (teacher == null){
                System.out.println("---------------该用户不存在-----------------");
            }
        }
    }
    public void delTeacherToActivity(){
        System.out.println("请输入要删除老师的活动id: ");
        String activityId = scanner.next();
        System.out.println("请输入老师的id: ");
        String techerId = scanner.next();
        Activity activity = activitySystem.find(activityId);
        if (activity == null){
            System.out.println("---------------查找活动不存在-----------------");
            return;
        }
        if (activity.delTeacher(techerId)) {
            System.out.println("---------------删除成功-----------------");
        } else {
            System.out.println("--------------id不存在，删除失败-------------------");
        }
    }

    public void addTeamToActivity(){
        System.out.println("请输入团队的id: ");
        String teamId = scanner.next();
        System.out.println("请输入团队要加入的活动id: ");
        String activityId = scanner.next();
        Activity activity = activitySystem.find(activityId);
        Team team = userSystem.findTeam(teamId);
        if ((activity != null) && (team != null)){
            activity.addTeam(team);
        }else {
            if (activity ==null) {
                System.out.println("---------------该活动不存在-----------------");
            }
            if (team == null){
                System.out.println("---------------该团队不存在-----------------");
            }
        }
    }
    public void delTeamToActivity(){
        System.out.println("请输入要删除团队的活动id: ");
        String activityId = scanner.next();
        System.out.println("请输入团队的id: ");
        String teamId = scanner.next();
        Activity activity = activitySystem.find(activityId);
        if (activity == null){
            System.out.println("---------------查找活动不存在-----------------");
            return;
        }
        if (activity.delTeam(teamId)) {
            System.out.println("---------------删除成功-----------------");
        } else {
            System.out.println("--------------id不存在，删除失败-------------------");
        }
    }

    //此处add方法逻辑相同，故只对增加活动中的addArtisticActivity做注释
    public void addActivityChoice(){
        String choice;
        System.out.println("---------------添加活动-----------------");
        System.out.println("---------------请选择你要添加的活动类型----------------");
        System.out.println("\t\t1.    文艺活动");
        System.out.println("\t\t2.    讲座活动");
        System.out.println("\t\t3.    党日活动");
        choice = scanner.next();
        switch (choice) {
            case "1":
                addArtisticActivity();
                break;
            case "2":
                addLectureActivity();
                break;
            case "3":
                addPartyActivity();
                break;
            default:
                System.out.print("错误,请输入数字（1-3）");
        }

    }
    //该方法用于增加系统中的活动
    public void addArtisticActivity(){
        //依次输入你要增加的活动信息，注意Date类必须按指定格式输入，否则程序将会崩溃
        System.out.println("id：");
        String id = scanner.next();
        System.out.println("name：");
        String name = scanner.next();
        System.out.println("description：");
        String description = scanner.next();
        System.out.println("site：");
        String site = scanner.next();
        System.out.println("startime(月.日)：");
        String startime =  scanner.next();
        System.out.println("endtime(月.日)：");
        String endtime = scanner.next();
        System.out.println("type：");
        String type = scanner.next();
        //通过构造器新建一个activity类
        Activity activity = new ArtisticActivity(id,name,description,site,startime,endtime,type);
        //调用activitySystem的add方法，添加
        if (activitySystem.add(activity)){
            System.out.println("添加成功");
        }else {
            System.out.println("添加失败");
        }
    }
    public void addLectureActivity(){

        System.out.println("id：");
        String id = scanner.next();
        System.out.println("name：");
        String name = scanner.next();
        System.out.println("description：");
        String description = scanner.next();
        System.out.println("site：");
        String site = scanner.next();
        System.out.println("startime(月.日)：");
        String startime =  scanner.next();
        System.out.println("endtime(月.日)：");
        String endtime = scanner.next();
        System.out.println("keySpeaker：");
        String keySpeaker = scanner.next();
        Activity activity = new LectureActivity(id,name,description,site,startime,endtime,keySpeaker);
        if (activitySystem.add(activity)){
            System.out.println("添加成功");
        }else {
            System.out.println("添加失败");
        }
    }
    public void addPartyActivity(){

        System.out.println("id：");
        String id = scanner.next();
        System.out.println("name：");
        String name = scanner.next();
        System.out.println("description：");
        String description = scanner.next();
        System.out.println("site：");
        String site = scanner.next();
        System.out.println("startime(月.日)：");
        String startime =  scanner.next();
        System.out.println("endtime(月.日)：");
        String endtime = scanner.next();
        System.out.println("theme：");
        String theme = scanner.next();
        System.out.println("classification：");
        String classification = scanner.next();
        Activity activity = new PartyActivity(id,name,description,site,startime,endtime,theme,classification);
        if (activitySystem.add(activity)){
            System.out.println("添加成功");
        }else {
            System.out.println("添加失败");
        }

    }

    public void addUserChoice(){
        String choice;
        System.out.println("---------------添加用户-----------------");
        System.out.println("---------------请选择你要添加的用户类型----------------");
        System.out.println("\t\t1.    学生");
        System.out.println("\t\t2.    老师");
        System.out.println("\t\t3.    主办方");
        choice = scanner.next();
        switch (choice) {
            case "1":
                addStudent();
                break;
            case "2":
                addTeacher();
                break;
            case "3":
                addOrganizer();
                break;
            default:
                System.out.print("错误,请输入数字（1-3）");
        }

    }
    public void addStudent(){

        System.out.println("id：");
        String id = scanner.next();
        System.out.println("name：");
        String name = scanner.next();
        System.out.println("phoneNo：");
        String phoneNo = scanner.next();
        System.out.println("email：");
        String email = scanner.next();
        System.out.println("studentNo：");
        String studentNo =  scanner.next();
        System.out.println("gender：");
        String gender = scanner.next();
        System.out.println("grade：");
        String grade = scanner.next();
        System.out.println("department：");
        String department = scanner.next();
        User user = new Student(id,name,phoneNo,email,studentNo,gender,grade,department);
        if (userSystem.add(user)){
            System.out.println("添加成功");
        }else {
            System.out.println("添加失败");
        }
    }
    public void addTeacher(){

        System.out.println("id：");
        String id = scanner.next();
        System.out.println("name：");
        String name = scanner.next();
        System.out.println("phoneNo：");
        String phoneNo = scanner.next();
        System.out.println("email：");
        String email = scanner.next();
        System.out.println("teacherNo：");
        String teacherNo =  scanner.next();
        System.out.println("department：");
        String department = scanner.next();
        User user = new Teacher(id,name,phoneNo,email,teacherNo,department);
        if (userSystem.add(user)){
            System.out.println("添加成功");
        }else {
            System.out.println("添加失败");
        }
    }
    public void addOrganizer(){

        System.out.println("id：");
        String id = scanner.next();
        System.out.println("name：");
        String name = scanner.next();
        System.out.println("phoneNo：");
        String phoneNo = scanner.next();
        System.out.println("email：");
        String email = scanner.next();
        System.out.println("unit：");
        String unit =  scanner.next();
        User user = new Organizer(id,name,phoneNo,email,unit);
        if (userSystem.add(user)){
            System.out.println("添加成功");
        }else {
            System.out.println("添加失败");
        }

    }

    //此处del方法逻辑相同，故只对delActivity做注释
    //该方法用于删除系统中的活动
    public void delActivity() {
        System.out.println("---------------删除活动-----------------");
        System.out.println("请输入删除活动的id：");
        String delId = scanner.next();
        //调用activitySystem类的del方法删除活动
        if (activitySystem.del(delId)) {
            System.out.println("---------------删除成功-----------------");
        } else {
            System.out.println("--------------id不存在，删除失败-------------------");
        }
    }
    public void delUser() {
        System.out.println("---------------删除用户-----------------");
        System.out.println("请输入删除用户的id：");
        String delId = scanner.next();
        if (userSystem.del(delId)) {
            System.out.println("---------------删除成功-----------------");
        } else {
            System.out.println("--------------id不存在，删除失败-------------------");
        }
    }

    //此处update方法逻辑相同，故只对updateActivity做注释
    //该方法用于修改系统中的活动信息
    public void updateActivity(){
        System.out.println("---------------修改活动-----------------");
        System.out.println("请输入修改活动的编号：");
        String updateId = scanner.next();
        //先找到要修改的活动
        //然后依次通过set方法修改信息
        Activity activity = activitySystem.find(updateId);
        if (activity == null){
            System.out.println("--------------活动id不存在-------------------");
            return;
        }
        System.out.println("id(" + activity.getId() + ")：");
        String id = readString(8,"");
        if (!"".equals(id)){
            activity.setId(id);
        }

        System.out.println("name(" + activity.getName() + ")：");
        String name = readString(8,"");
        if (!"".equals(name)){
            activity.setName(name);
        }

        System.out.println("description(" + activity.getDescription() + ")：");
        String description = readString(8,"");
        if (!"".equals(description)){
            activity.setDescription(description);
        }

        System.out.println("site(" + activity.getSite() + ")：");
        String site = readString(8,"");
        if (!"".equals(site)){
            activity.setSite(site);
        }

        System.out.println("startime(" + activity.getStartime() + ")(月.日)：");
        String startime = readString(6,"");
        if (!"".equals(startime)){
            activity.setStartime(startime);
        }


        System.out.println("endtime(" + activity.getEndtime() + ")(月.日)：");
        String endtime = readString(6,"");
        if (!"".equals(endtime)){
            activity.setEndtime(endtime);
        }

        //此处为先判断是哪一类型的活动再进行对应子类的属性进行修改
        if (activity instanceof ArtisticActivity){
            System.out.println("type(" + ((ArtisticActivity) activity).getType() + ")：");
            String type = readString(8,"");
            if (!"".equals(type)){
                ((ArtisticActivity) activity).setType(type);
            }
        }

        if (activity instanceof LectureActivity){
            System.out.println("keySpeaker(" + ((LectureActivity) activity).getKeySpeaker()+ ")：");
            String keySpeaker = readString(8,"");
            if (!"".equals(keySpeaker)){
                ((LectureActivity) activity).setKeySpeaker(keySpeaker);
            }
        }

        if (activity instanceof PartyActivity){
            System.out.println("theme(" +  ((PartyActivity) activity).getTheme() + ")：");
            String theme = readString(8,"");
            if (!"".equals(theme)){
                ((PartyActivity) activity).setTheme(theme);
            }
            System.out.println("classification(" +  ((PartyActivity) activity).getClassification() + ")：");
            String classification = readString(8,"");
            if (!"".equals(classification)){
                ((PartyActivity) activity).setClassification(classification);
            }
        }

        System.out.println("--------------修改活动成功-------------------");
    }
    public void updateUser(){
        System.out.println("---------------修改用户-----------------");
        System.out.println("请输入修改用户的编号：");
        String updateId = scanner.next();
        User user = userSystem.find(updateId);
        if (user == null){
            System.out.println("--------------用户id不存在-------------------");
            return;
        }
        System.out.println("id(" + user.getId() + ")：");
        String id = readString(8,"");
        if (!"".equals(id)){
            user.setId(id);
        }

        System.out.println("name(" + user.getName() + ")：");
        String name = readString(8,"");
        if (!"".equals(name)){
            user.setName(name);
        }

        System.out.println("phoneNo(" + user.getPhoneNo() + ")：");
        String phoneNo = readString(11,"");
        if (!"".equals(phoneNo)){
            user.setPhoneNo(phoneNo);
        }

        System.out.println("email(" + user.getEmail() + ")：");
        String email = readString(20,"");
        if (!"".equals(email)){
            user.setEmail(email);
        }

        if (user instanceof Student){
            System.out.println("studentNo(" + ((Student) user).getStudentNo() + ")：");
            String studentNo = readString(20,"");
            if (!"".equals(studentNo)){
                ((Student) user).setStudentNo(studentNo);
            }

            System.out.println("gender(" + ((Student)  user).getGender() + ")：");
            String gender = readString(20,"");
            if (!"".equals(gender)){
                ((Student) user).setGender(gender);
            }

            System.out.println("grade(" + ((Student) user).getGrade() + ")：");
            String grade = readString(20,"");
            if (!"".equals(grade)){
                ((Student) user).setGrade(grade);
            }

            System.out.println("department(" + ((Student) user).getDepartment() + ")：");
            String department = readString(20,"");
            if (!"".equals(department)){
                ((Student) user).setDepartment(department);
            }
        }

        if (user instanceof Teacher){
            System.out.println("teacherNo(" +  ((Teacher) user).getTeacherNo() + ")：");
            String teacherNo = readString(20,"");
            if (!"".equals(teacherNo)){
                ((Teacher) user).setTeacherNo(teacherNo);
            }

            System.out.println("department(" +  ((Teacher) user).getDepartment() + ")：");
            String department = readString(20,"");
            if (!"".equals(department)){
                ((Teacher) user).setDepartment(department);
            }
        }

        if (user instanceof Organizer){
            System.out.println("unit(" +   ((Organizer) user).getUnit() + ")：");
            String unit = readString(20,"");
            if (!"".equals(unit)){
                ((Organizer) user).setUnit(unit);
            }
        }

        System.out.println("--------------修改用户成功-------------------");
    }

    //此处find方法逻辑相同，故只对findActivity做注释
    //该方法用于找到系统中的活动信息
    public void findActivity(){
        System.out.println("---------------查找活动-----------------");
        System.out.println("请输入要查找的id：");
        String findid = scanner.next();
        //通过activitySystem类的find方法找到并传回所要找的activity
        Activity activity = activitySystem.find(findid);
        if (activity != null){
            System.out.println(activity);
        }else {
            System.out.println("---------------查找活动不存在-----------------");
        }
    }
    public void findUser(){
        System.out.println("---------------查找用户-----------------");
        System.out.println("请输入要查找的id：");
        String findid = scanner.next();
        User user = userSystem.find(findid);
        if (user != null){
            System.out.println(user);
        }else {
            System.out.println("---------------查找用户不存在-----------------");
        }
    }

    //该方法用于找到对应时间有哪些活动正在举办
    public void getActivityByDate(){
        System.out.println("---------------查找活动-----------------");
        System.out.println("请输入要查找的时间(输入格式为月.日.时)：");
        String findtime = scanner.next();
        //通过activitySystem类的getActivity方法找到并传回所要找的activity
        Activity activity[] = activitySystem.getActivity(findtime);
        if (activity[0] == null){
            System.out.println("---------------该时间段无活动-----------------");
            return;
        }
        //依次输入找到的活动
        for (int i = 0;i <activity .length;i++) {
            if (activity[i] == null) {
                break;
            }
            System.out.println(activity[i]);
        }
    }

    //该方法用于找到团队参加了多少活动
    public void checkActivityNumOfTeam() {
        System.out.println("请输入要查询的团队的id: ");
        String teamId = scanner.next();
        //先锁定要查的团队
        Team team = userSystem.findTeam(teamId);
        if (team == null) {
            System.out.println("---------------该团队不存在-----------------");
        } else {
            //此处说明，将团队添加或删除入活动的方法中每次调用都会使team类的Count属性对应加一或者减一
            //调用team类的getCount方法获得数量
            System.out.println(team.getCount());
        }
    }

    //以下两个方法逻辑相同，故只在showaAtivity方法中做注释
    //该方法显示所有的活动信息
    public void showActivity(){
        //先调用activitySystem类的show方法获得所有的activity[]数组
        Activity activity[] = activitySystem.show();
        //当数组执行到为空时结束方法
        for (int i = 0;i <activity .length;i++) {
            if (activity[i] == null) {
                break;
            }
            //此处设计为了有序输出活动信息，先输出所有的ArtisticActivity，而不是按活动添加顺序输出
            //通过instanceof方法判断activity的运行类型，若为ArtisticActivity则输出，否则continue继续循环
            if (activity[i] instanceof ArtisticActivity){
                System.out.println("\n文艺活动：" + activity[i] );
                //分别通过调用activity类中的toStringOrganizer，toStringTeacher，toStringTeam得到该活动下包含的老师，主办方，团队
                Organizer organizer[] = activity[i].toStringOrganizer();
                Teacher teacher[] = activity[i].toStringTeacher();
                Team team[] = activity[i].toStringTeam();
                System.out.print("活动主办方：" );
               //for循环输出主办方信息
                for (int j = 0;j < organizer.length;j++) {
                    if (organizer[j] == null) {
                        break;
                    }
                    System.out.println("\t" + organizer[j]);
                }
                System.out.print("\n活动教师：" );
                //for循环输出老师信息
                for (int k = 0;k < teacher.length;k++) {
                    if (teacher[k] == null) {
                        break;
                    }
                    System.out.println("\t" + teacher[k]);
                }
                System.out.print("\n参与活动的团队：" );
                //for循环输出团队信息
                for (int l = 0;l < team.length;l++) {
                    if (team[l] == null) {
                        break;
                    }
                    System.out.print("\t" +team[l]);
                    System.out.print("\t指导老师:");
                    for (int m = 0;m < team[i].getTeachers().length;m++) {
                        if (team[i].getTeachers()[m] == null) {
                            break;
                        }
                        System.out.print( team[i].getTeachers()[m].getTeacherNo());
                    }
                    System.out.print("\t团队成员:");
                    for (int n = 0;n < team[i].getStudents().length;n++) {
                        if (team[i].getStudents()[n] == null) {
                            break;
                        }
                        System.out.print( team[i].getStudents()[n].getStudentNo());
                    }
                }
            }else {
                continue;
            }
        }
//下面两处循环和第一个逻辑相同不在注释
        for (int i = 0;i <activity .length;i++) {
            if (activity[i] == null) {
                break;
            }
            if (activity[i] instanceof LectureActivity){
                System.out.println("\n讲座活动：" + activity[i] );
                Organizer organizer[] = activity[i].toStringOrganizer();
                Teacher teacher[] = activity[i].toStringTeacher();
                Team team[] = activity[i].toStringTeam();
                System.out.print("活动主办方：" );
                for (int j = 0;j < organizer.length;j++) {
                    if (organizer[j] == null) {
                        break;
                    }
                    System.out.println("\t" + organizer[j]);
                }
                System.out.print("\n活动教师：" );
                for (int k = 0;k < teacher.length;k++) {
                    if (teacher[k] == null) {
                        break;
                    }
                    System.out.println("\t" + teacher[k]);
                }
                System.out.print("\n参与活动的团队：" );
                for (int l = 0;l < team.length;l++) {
                    if (team[l] == null) {
                        break;
                    }
                    System.out.print("\t" +team[l]);
                    System.out.print("\t指导老师:");
                    for (int m = 0;m < team[i].getTeachers().length;m++) {
                        if (team[i].getTeachers()[m] == null) {
                            break;
                        }
                        System.out.print( team[i].getTeachers()[m].getTeacherNo());
                    }
                    System.out.print("\t团队成员:");
                    for (int n = 0;n < team[i].getStudents().length;n++) {
                        if (team[i].getStudents()[n] == null) {
                            break;
                        }
                        System.out.print( team[i].getStudents()[n].getStudentNo());
                    }
                }
            }else {
                continue;
            }
        }

        for (int i = 0;i <activity .length;i++) {
            if (activity[i] == null) {
                break;
            }
            if (activity[i] instanceof PartyActivity){
                System.out.println("\n党日活动：" + activity[i] );
                Organizer organizer[] = activity[i].toStringOrganizer();
                Teacher teacher[] = activity[i].toStringTeacher();
                Team team[] = activity[i].toStringTeam();
                System.out.print("活动主办方：" );
                for (int j = 0;j < organizer.length;j++) {
                    if (organizer[j] == null) {
                        break;
                    }
                    System.out.println("\t" + organizer[j]);
                }
                System.out.print("\n活动教师：" );
                for (int k = 0;k < teacher.length;k++) {
                    if (teacher[k] == null) {
                        break;
                    }
                    System.out.println("\t" + teacher[k]);
                }
                System.out.print("\n参与活动的团队：" );
                for (int l = 0;l < team.length;l++) {
                    if (team[l] == null) {
                        break;
                    }
                    System.out.print("\t" +team[l]);
                    System.out.print("\t指导老师:");
                    for (int m = 0;m < team[i].getTeachers().length;m++) {
                        if (team[i].getTeachers()[m] == null) {
                            break;
                        }
                        System.out.print( team[i].getTeachers()[m].getTeacherNo());
                    }
                    System.out.print("\t团队成员:");
                    for (int n = 0;n < team[i].getStudents().length;n++) {
                        if (team[i].getStudents()[n] == null) {
                            break;
                        }
                        System.out.print( team[i].getStudents()[n].getStudentNo());
                    }
                }
            }else {
                continue;
            }
        }
    }
    public void showUsers(){
        User user[] = userSystem.show();
        for (int i = 0;i <user .length;i++) {
            if (user[i] == null) {
                break;
            }
            if (user[i] instanceof Student){
                System.out.println("学生：" +user[i] );
            }else {
                continue;
            }
        }

        for (int i = 0;i <user .length;i++) {
            if (user[i] == null) {
                break;
            }
            if (user[i] instanceof Teacher){
                System.out.println("老师：" +user[i] );
            }else {
                continue;
            }
        }

        for (int i = 0;i <user .length;i++) {
            if (user[i] == null) {
                break;
            }
            if (user[i] instanceof Organizer){
                System.out.println("主办方：" +user[i] );
            }else {
                continue;
            }
        }
    }

    //该方法创建团队
    public void createTeam() {
        System.out.println("teamId：");
        String teamId = scanner.next();
        System.out.println("teamName：");
        String teamName = scanner.next();
        System.out.println("department：");
        String department = scanner.next();
        System.out.println("craetorId：");
        String craetorId = scanner.next();
        //输入信息并调用creat方法创建团队
        userSystem.create(craetorId, teamId, teamName, department);
    }

    //以下两个方法逻辑相同，故只在addStudentToTeam方法中做注释
    //该方法将学生成员添加入团队
    public void addStudentToTeam() {
        System.out.println("请输入活动创造者的学生id: ");
        String creatorId = scanner.next();
        System.out.println("请输入学生的id: ");
        String studentId = scanner.next();
        System.out.println("请输入学生要加入的团队的id: ");
        String teamId = scanner.next();
        //找到对应的团队
        Team team = userSystem.findTeam(teamId);
        //找到对应的学生
        Student student = (Student) userSystem.find(studentId);
        if ((team != null) && (student != null)) {
           //如果都存在，则调用team类的addStuden方法添加
            team.addStudent(student);
        } else {
            if (team == null) {
                System.out.println("---------------该团队不存在-----------------");
            }
            if (student == null) {
                System.out.println("---------------该用户不存在-----------------");
            }
        }
    }
    public void addTeacherToTeam() {
        System.out.println("请输入活动创造者的学生id: ");
        String creatorId = scanner.next();
        System.out.println("请输入老师的id: ");
        String techerId = scanner.next();
        System.out.println("请输入老师要加入的团队的id: ");
        String teamId = scanner.next();
        Team team = userSystem.findTeam(teamId);
        Teacher teacher = (Teacher) userSystem.find(techerId);
        if ((team != null) && (teacher != null)) {
            team.addTeacher(teacher);
        } else {
            if (team == null) {
                System.out.println("---------------该团队不存在-----------------");
            }
            if (teacher == null) {
                System.out.println("---------------该用户不存在-----------------");
            }
        }
    }

    //以下方法均为相同逻辑
    //dowhile循环，当选择退出选项时将判断条件置为false，退出循环，选择其他选项时进入对应功能的方法
    public void choice3() {
        String choice;
        boolean judge = true;
        do {
            System.out.println("\t\t\t----------------请选择你要进行的功能-------------------");
            System.out.println("\t\t\t1.  增加用户信息");
            System.out.println("\t\t\t2.  删除用户信息");
            System.out.println("\t\t\t3.  改变用户信息");
            System.out.println("\t\t\t4.  查找用户信息");
            System.out.println("\t\t\t5.  退出");
            choice = scanner.next();
            switch (choice) {
                case "1":
                    addUserChoice();
                    break;
                case "2":
                    delUser();
                    break;
                case "3":
                    updateUser();
                    break;
                case "4":
                    findUser();
                    break;
                case "5":
                    judge = false;
                    break;
                default:
                    System.out.print("错误,请输入数字（1-5）");
            }
        }while(judge);
    }
    public void choice4() {
        String choice;
        boolean judge = true;
       do {
           System.out.println("\t\t\t----------------请选择你要进行的功能-------------------");
           System.out.println("\t\t\t1.  增加活动信息");
           System.out.println("\t\t\t2.  删除活动信息");
           System.out.println("\t\t\t3.  改变活动信息");
           System.out.println("\t\t\t4.  查找活动信息");
           System.out.println("\t\t\t5.  退出");
           choice = scanner.next();
           switch (choice) {
               case "1":
                   addActivityChoice();
                   break;
               case "2":
                   delActivity();
                   break;
               case "3":
                   updateActivity();
                   break;
               case "4":
                   findActivity();
                   break;
               case "5":
                   judge = false;
                   break;
               default:
                   System.out.print("错误,请输入数字（1-5）");
           }
       }while(judge);
    }
    public void choice6() {
        String choice;
        boolean judge = true;
        do {
            System.out.println("\t\t\t----------------请选择你要进行的功能-------------------");
            System.out.println("\t\t\t1.  将团队添加到某项活动中（报名）");
            System.out.println("\t\t\t2.  从某项活动中删除团队（撤销报名）");
            System.out.println("\t\t\t3.  退出");
            choice = scanner.next();
            switch (choice) {
                case "1":
                    addTeamToActivity();
                    break;
                case "2":
                    delTeamToActivity();
                    break;
                case "3":
                    judge = false;
                    break;
                default:
                    System.out.print("错误,请输入数字（1-3）");
            }
        }while(judge);
    }
    public void choice7() {
        String choice;
        boolean judge = true;
        do {
            System.out.println("\t\t\t----------------请选择你要进行的功能-------------------");
            System.out.println("\t\t\t1.  将教师添加到某项活动中");
            System.out.println("\t\t\t2.  从某项活动中删除教师");
            System.out.println("\t\t\t3.  退出");
            choice = scanner.next();
            switch (choice) {
                case "1":
                    addTeacherToActivity();
                    break;
                case "2":
                    delTeacherToActivity();
                    break;
                case "3":
                    judge = false;
                    break;
                default:
                    System.out.print("错误,请输入数字（1-3）");
            }
        }while(judge);
    }
    public void choice8() {
        String choice;
        boolean judge = true;
        do {
            System.out.println("\t\t\t----------------请选择你要进行的功能-------------------");
            System.out.println("\t\t\t1.  将主办方添加到某项活动中");
            System.out.println("\t\t\t2.  从某项活动中删除主办方");
            System.out.println("\t\t\t3.  退出");
            choice = scanner.next();
            switch (choice) {
                case "1":
                    addOrganizerToActivity();
                    break;
                case "2":
                    delOrganizerToActivity();
                    break;
                case "3":
                    judge = false;
                    break;
                default:
                    System.out.print("错误,请输入数字（1-3）");
            }
        }while(judge);
    }
    public void choice10() {
        String choice;
        boolean judge = true;
        do {
            System.out.println("\t\t\t----------------请选择你要进行的功能-------------------");
            System.out.println("\t\t\t1.  创建团队");
            System.out.println("\t\t\t2.  学生向自己创建的团队添加学生成员");
            System.out.println("\t\t\t3.  学生向自己创建的团队添加指导老师");
            System.out.println("\t\t\t4.  退出");
            choice = scanner.next();
            switch (choice) {
                case "1":
                    createTeam();
                    break;
                case "2":
                    addStudentToTeam();
                    break;
                case "3":
                    addTeacherToTeam();
                    break;
                case "4":
                    judge = false;
                    break;
                default:
                    System.out.print("错误,请输入数字（1-4）");
            }
        }while(judge);
    }

    //显示主菜单
    //dowhile循环，当选择退出选项时将判断条件置为false，退出循环，选择其他选项时进入对应功能的方法
    public void menu() {
        do {
            System.out.println("\n\n---------------校园活动管理系统----------------");
            System.out.println("\t\t\t1.  查看所有的用户（学生、教师、主办方）信息");
            System.out.println("\t\t\t2.  查看所有的活动信息");
            System.out.println("\t\t\t3.  增、删、改、查（通过ID）学生/教师/主办方信息");
            System.out.println("\t\t\t4.  增、删、改、查（通过ID）活动信息");
            System.out.println("\t\t\t5.  根据时间筛选活动（查看某一时间有哪些活动正在举行）");
            System.out.println("\t\t\t6.  将团队添加到某项活动中（报名）、从某项活动中删除团队（撤销报名）");
            System.out.println("\t\t\t7.  将教师添加到某项活动中、从某项活动中删除教师");
            System.out.println("\t\t\t8.  将主办方添加到某项活动中、从某项活动中删除主办方");
            System.out.println("\t\t\t9.  检查某个团队是否参加了多项活动，返回其参加的活动数目");
            System.out.println("\t\t\t10.  创建团队、学生向自己创建的团队添加学生成员（学生）、学生向自己创建的团队添加指导老师（教师）");
            System.out.println("\t\t\t11.  退出");
            System.out.println("请选择（1-11）：");
            key = scanner.next();
            switch (key) {
                case "1":
                    showUsers();
                    break;
                case "2":
                    showActivity();
                    break;
                case "3":
                    choice3();
                    break;
                case "4":
                    choice4();
                    break;
                case "5":
                    getActivityByDate();
                    break;
                case "6":
                    choice6();
                    break;
                case "7":
                    choice7();
                    break;
                case "8":
                    choice8();
                    break;
                case "9":
                    checkActivityNumOfTeam();
                    break;
                case "10":
                    choice10();
                    break;
                case "11":
                    judgment = false;
                    break;
                default:
                    System.out.print("错误,请输入数字（1-11）");
            }
        } while (judgment);
    }
}
